﻿

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <link href="~/Content/layui/css/layui.css" rel="stylesheet" />
    <script src="~/Content/layui/layui.js"></script>
    <script src="~/Content/myjs/jquery-1.10.2.min.js"></script>
</head>
<body style="padding:40px 0 30px 80px;">
    <div class="layui-col-md8">
        <form class="layui-form layui-form-pane" lay-filter="form_add" @*action="/Admin/UserInfo/Update"*@>

            <div class="layui-form-item">
                <label class="layui-form-label">用户账号</label>
                <div class="layui-input-inline">
                    <input type="text" name="UserId" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" value="@ViewBag.model.UserId" readonly="readonly" style="color:red;font-weight:600">
                </div>
                <label class="layui-form-label">用户名字</label>
                <div class="layui-input-inline">
                    <input type="text" name="UserName" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" value="@ViewBag.model.UserName">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">手机号码</label>
                <div class="layui-input-inline">
                    <input type="text" name="PhoneNum" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" value="@ViewBag.model.PhoneNum">
                </div>
                <label class="layui-form-label">邮箱地址</label>
                <div class="layui-input-inline ">
                    <input type="text" name="Email" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" value="@ViewBag.model.Email">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">性别</label>
                <div class="layui-input-inline ">
                    <select name="Sex" id="mysex">
                        <option value=1>男</option>
                        <option value=2>女</option>
                    </select>
                </div>
                <label class="layui-form-label">部门</label>
                <div class="layui-input-inline ">
                    <select name="DepartmentId"  id="mydepartment">
                        @foreach (var item in @ViewBag.departmentList)
                        {
                            <option value=@item.DepartmentId>@item.DepartmentName</option>
                        }
                    </select>
                </div>
            </div>





            <div class="layui-form-item" style="text-align:center;margin:0 90px 0 0;">
                <button class="layui-btn" lay-submit="" lay-filter="formDemo">确认修改</button>
            </div>
        </form>
    </div>

    <script>

        //给下拉框赋值
        $('#mysex').val(@ViewBag.model.Sex);
        $('#mydepartment').val("@ViewBag.model.DepartmentId");

        layui.use(['form', 'layedit', 'laydate'], function () {
            var form = layui.form
            var layedit = layui.layedit
            //自定义验证规则
            form.verify({
                maxlength: function (value) {
                    if (value.length >16) {
                        return '不能超过16个字符';
                    }
                }
            });
                //监听提交
            form.on('submit(formDemo)', function (data) {
                debugger;
                $.ajax({
                    url: '/User/Update',
                    method: 'post',
                    data: data.field,
                    success: function (data) {

                        if (data == "ok") {
                            layer.alert("修改成功！");
                            setTimeout(function () {
                                //休眠1秒后页面跳转
                                window.location.href = "/User/UpdateIndex?id="+@ViewBag.model.Id+"";
                                //关闭当前弹框
                                //var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                //parent.layer.close(index); //再执行关闭
                            }, 2000);


                        } else {
                            layer.alert("修改失败");
                        }
                    }
                });
                return false;//防止页面跳转
            });
        });
    </script>

</body>
</html>
